﻿$(function () {
    $('#phone').focus();  //当前页面输入框选中

    //主页面快捷键
    $(document).on('keydown', function (e) {
        switch (e.keyCode) {
            case 13:    //回车
                e.preventDefault();
                var phone = $('#phone').val();
                var password = $('#password').val();
                login(phone, password);
                break;
        }
    })
});

var url = 'http://mybok.skydige.com/';
var myreg = /^1[34578]\d{9}$/;
//登陆方法
function login(phone, password) {
    if (phone == "" || password == "") {
        //账户名或密码不能为空？
        message('message.html?t=101', '300px', '200px');
    }
    else {
        if (!myreg.test(phone)) {
            message('message.html?t=102', '300px', '200px');
        }
        else {
            $.ajax({

                url: url + 'login',                                         //请求地址
                type: 'POST',                                                   //请求类型
                dataType: "json",                                               //返回值类型
                data: {"phone": phone, "password": password},                                 //参数
                success: function (data) {


                    //alert(url);

                    if (data.code == 200 && data.data != null && data.data != "") {

                        $.cookie('sysuid', data.data.info.uid);
                        $.cookie('token', data.token, 72000);
                        $.cookie('storeName', data.data.storeConfig.storeName);
                        $.cookie('realName', data.data.info.real_name);
                        $.cookie('sysnumber', data.data.info.number);
                        $.cookie('sysnumber', data.data.info.number);


                        window.location.href = "index.html";
                    }
                    else {
                        message('message.html?t=502', '300px', '200px');
                    }
                }
            })
        }
    }
}